<?php
/**
 *
 * @author Strawberry🍓
 * @date 2021-05-21 4:08 下午
 *
 */

namespace app\common\model\tang;


use app\common\impl\Comm;
use app\common\model\CommonBaseModel;
use Jrk\Tree;

class RepairRecord extends CommonBaseModel implements Comm
{

    public function getAdminPageData($param = [], $order = 'id asc')
    {
        // TODO: Implement getAdminPageData() method.
        $where=[];

        if (isset($param['merchant_id']) && $param['merchant_id']) {
            $where[] = ['merchant_id','=',$param['merchant_id']];
        }
        if (isset($param['repair_type_id']) && $param['repair_type_id']) {
            $where[] = ['repair_type_id','=',$param['repair_type_id']];
        }
        if (isset($param['status']) && $param['status']!=-1) {
            $where[] = ['status','=',$param['status']];
        }
        if (isset($param['create_time']) && $param['create_time']) {
            $time = explode('~',$param['create_time']);
            $where[] = ['create_time','between',[strtotime($time[0]),strtotime($time[1])]];
        }
        $data = self::where($where)->with(['repairType','merchant','cost'])->order($order)->page(PAGE)->limit(LIMIT)->select()->toArray();
        $count = self::where($where)->count("id");
        return parent::ajaxResult($data, $count);

//        return parent::ajaxResult($data, $count);
    }

    public function delById($id)
    {
        // TODO: Implement delById() method.
    }

    public function doAll($data)
    {
        // TODO: Implement doAll() method.
        return parent::doAllData($data);
    }

    public function repairType(): \think\model\relation\HasOne
    {
        return $this->hasOne(RepairType::class,'id','repair_type_id');
    }
    public function merchant()
    {
        return $this->hasOne(Merchant::class,'id','merchant_id')->field('id,name');
    }
    public function cost(){
        return $this->hasOne(Cost::class,'id','cost_id')->field('id,amount,order_sn as order_no,pay_status');
    }
}